<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <!--1.添加视口标签 快捷方式：meta:vp -->
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"/>
    <!--2.设置网页渲染模式  快捷方式：meta:compat  -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <!--3.把bootstrap 核心样式（压缩版）引入-->
    <link rel="stylesheet" href="/static/css/bootstrap.min.css"/>
    <title>发布</title>
    <!--6.针对于IE9 以下浏览器做兼容性处理 快捷方式：cc:ie -->
    <!--[if lt IE9 ]>
    <script src="js/html5shiv.min.js"></script>
    <script src="js/respond.min.js"></script>
    <![endif]-->
    <style>
        .navbar-inverse .navbar-nav > li > a {
            color: greenyellow;
        }

        li span {
            line-height: 50px;
            color: white;
            margin-left: 50px;
            margin-right: 200px;
        }
    </style>
</head>
<body>
<div id="main-nav" class="navbar navbar-inverse bs-docs-nav" role="banner">
    <div class="container">
        <div class="navbar-header responsive-logo">
            <div class="navbar-brand">
                <a href="/"><img src="/static/img/loggo.png" style="margin-top: -19px"></a>
            </div>
        </div>
        <nav class="navbar-collapse collapse" role="navigation" id="bs-navbar-collapse">
            <ul class="nav navbar-nav navbar-right responsive-nav main-nav-list">
                <li><span id="navbar-nav-list-home" href="">欢迎登陆</span></li>
                <li><span id="navbar-nav-list-testimonials" href="">用户名:{{ request.user }}</span></li>
                <li><a id="navbar-nav-list-pricing" class="btn btn-primary" href="/accounts/logout"> 注销</a></li>
                <li><a target="_blank" id="admin" href="/admin" class="btn signup-button btn-danger">后台管理</a></li>
                <li><a target="_blank" id="admin" href="/发布统计" class="btn signup-button btn-info">发布统计</a></li>
            </ul>
        </nav>
    </div>
</div>

<div class="form-group clearfix">
    <label for="" class="control-label col-md-4 text-right"><h4>要切换的分支:</h4></label>
    <div class="col-md-4">
        <input class="form-control" name="Branch" type="text" placeholder="填写要切换的分支,不填写则为默认不切换">
    </div>
</div>
<div class="container text-center">
    <br><br>
    {% for i in data %}
        <div class="col-md-3">
            <h1>{{ i.发布的名字 }}</h1>
            <button type="button" class="btn {{ i.按钮样式 }} btn-lg ">{{ i.目录名 }}</button>
            <br>
        </div>
    {% endfor %}
</div>


{#    <div class="col-md-3">#}
{#        <h1>mma测试自测环境</h1>#}
{#        <button type="button" class="btn btn-info btn-lg ">mma_test</button>#}
{#    </div>#}


<!--模态框部分-->
<div class="modal fade  bs-example-modal-lg" id="myModal">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button class="close" data-dismiss="modal"><span>&times;</span></button>
                <h3 class="modal-title">发布日志信息查看</h3>
            </div>
            <div class="modal-body">
                <div class="form-group clearfix">
                    <label for="" class="control-label col-md-7 text-right">发布日志信息查看:</label>
                    <div class="col-md-12">
                        <textarea class="form-control" name="use" type="text"></textarea>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button class="btn btn-primary close-modal" data-dismiss="modal">关闭</button>
                {#                <button class="btn btn-success save">保存</button>#}
            </div>
        </div>
    </div>
</div>
<!--4.把jQuery 引入-->
<script src="/static/js/jquery-1.10.2.min.js"></script>
<!--5.把bootstrap 核心脚本文件（压缩版）引入-->
<script src="/static/js/bootstrap.min.js"></script>
<script>
    $(function () {
        $('button[type=button]').click(function () {
            $("#myModal").modal('show');//显示模态框
            var text = $(this).text();
            $('.col-md-12').html('<textarea class="form-control" style="color:green;height: 600px" id="' + text + '"></textarea>');
            $("#" + text).html("" + text + "开始发布，请稍等！");
            $(".modal-title").html("<h2>" + text + "开始发布，请稍等！<h2>");
            var Branch = $('input[name=Branch]').val();
            console.log('项目' + text);
            console.log('分支' + Branch);
            console.log("日志路径: /static/log/" + text+'.log');

            $.get("", {"text": text, "Branch": Branch}, function () {
            });

            function getlog() {

                $.ajax({
                    url: "/static/log/" + text + '.log',
                    success: function (loginfo) {
                        if (loginfo.indexOf("release_ok") > 0) {
                            $("#" + text).html(loginfo);
                            $(".modal-title").html("<h1>" + text + " Build complete! 发布完成！</h1>");
                            clearTimeout(timer1);//发布完成清除定时器
                            loginfo = '';
                        } else if (loginfo.indexOf("ERROR") > 0 && loginfo.indexOf("ERR!")) {
                            $("#" + text).html(loginfo);
                            $(".modal-title").html("<h1 style='color:red'>" + text + " BUILD FAILURE! 发布失败！</h1>");
                        }
                        else {
                            $("#" + text).html(loginfo);
                            $(".modal-title").html("<h2>" + text + " 正在发布中，请稍等！<h2>");
                        }
                    },
                    error: function () {
                        $(".modal-title").html("<h2>" + text + " 开始发布，请稍等！<h2>");
                    }
                });
            }

            {#            getlog();#}
            timer1 = setInterval(function () {
                //定时器要执行的代码
                getlog()
            }, 2500);

        })
    })
</script>
</body>
</html>